package homeWork;

import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

public class toMap {
    public static void main(String[] args) {
        String[] sArr = {"张三,北京", "李四,上海", "王五,深圳", "赵六,广州", "周七,黑龙江"};
        Map<String, String> map = Arrays.stream(sArr).collect(Collectors.toMap(new Function<String, String>() {
            @Override
            public String apply(String s) {
                String[] s1 = s.split("\\,");
                return s1[0];
            }
        }, new Function<String, String>() {
            @Override
            public String apply(String s) {
                String[] s1 = s.split("\\,");
                return s1[1];
            }
        }));
        Set<Map.Entry<String, String>> entries = map.entrySet();
        Iterator<Map.Entry<String, String>> iterator = entries.iterator();
        while(iterator.hasNext()){
            Map.Entry<String, String> next = iterator.next();
            System.out.println("姓名为："+next.getKey()+"-----"+"居住地为："+next.getValue());
        }
    }
}
